package main

import (
	"encoding/json"
	"fmt"

	"gitee.com/lflxp/treedb/models"
)

func main() {
	data1 := models.NewIndex()
	// data := models.GetById(data1, 0)
	// data := models.GetByArray(data1, []int{0, 0})
	// data.Label = "99g1ok"
	// data.Id = 1001
	// data.SetId(123).SetLabel("99g1").AddIndex(99)
	// jsoned, err := json.Marshal(data1)
	// if err != nil {
	// 	fmt.Println(err.Error())
	// }
	// fmt.Println(string(jsoned))

	models.GetByArray(data1, []int{0, 0}).AddChildren(
		&models.Index{
			Id:    10,
			Label: "2",
			Children: []*models.Index{
				&models.Index{
					Id:    11,
					Label: "2-1",
				},
				&models.Index{
					Id:    11,
					Label: "2-2",
				},
				&models.Index{
					Id:    10,
					Label: "2-3",
					Children: []*models.Index{
						&models.Index{
							Id:    11,
							Label: "2-3-1",
						},
						&models.Index{
							Id:    11,
							Label: "2-3-2",
						},
						&models.Index{
							Id:    11,
							Label: "2-3-3",
							Children: []*models.Index{
								&models.Index{
									Id:    10,
									Label: "2-3-3-1",
									Children: []*models.Index{
										&models.Index{
											Id:    11,
											Label: "2-3-3-1-1",
										},
										&models.Index{
											Id:    11,
											Label: "2-3-3-1-2",
										},
										&models.Index{
											Id:    11,
											Label: "2-3-3-1-3",
										},
									},
								},
							},
						},
					},
				},
			},
		},
	).AddChildren(
		&models.Index{
			Id:    10,
			Label: "2",
			Children: []*models.Index{
				&models.Index{
					Id:    11,
					Label: "2-1",
				},
				&models.Index{
					Id:    11,
					Label: "2-2",
				},
				&models.Index{
					Id:    10,
					Label: "2-3",
					Children: []*models.Index{
						&models.Index{
							Id:    11,
							Label: "2-3-1",
						},
						&models.Index{
							Id:    11,
							Label: "2-3-2",
						},
						&models.Index{
							Id:    11,
							Label: "2-3-3",
							Children: []*models.Index{
								&models.Index{
									Id:    10,
									Label: "2-3-3-1",
									Children: []*models.Index{
										&models.Index{
											Id:    11,
											Label: "2-3-3-1-1",
										},
										&models.Index{
											Id:    11,
											Label: "2-3-3-1-2",
										},
										&models.Index{
											Id:    11,
											Label: "2-3-3-1-3",
										},
									},
								},
							},
						},
					},
				},
			},
		},
	)

	models.Refresh(data1, nil)

	data := models.GetByArray(data1, []int{0, 0, 1, 2})
	json1, err := json.Marshal(data)
	if err != nil {
		fmt.Println(err.Error())
	}
	fmt.Println(string(json1))

}
